//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.taofuxn.admin.common.model;


import com.taofuxn.admin.common.exception.ExceptionEnum;
import lombok.Data;

@Data
public class BaseResults<T> {
    private Integer code;
    private String msg;
    private T data;

    public BaseResults() {
    }


    public static BaseResults genResults(Integer code, String msg) {
        return genResults(code,msg,null);
    }

    public static BaseResults genResults(Integer code, String msg,Object o) {
        BaseResults results = new BaseResults();
        results.setCode(code);
        results.setMsg(msg);
        results.setData(o);
        return results;
    }


    public static BaseResults success(Object obj) {
        return genResults(0,"SUCCESS",obj);
    }

    public static BaseResults success(String message,Object obj) {
        return genResults(0,message,obj);
    }

    public static BaseResults error(Object object) {
        return genResults(1500,"ERROR",object);
    }

    public static BaseResults fail(String msg) {
        return genResults(1500,msg,null);
    }

    public static BaseResults fail(ExceptionEnum ex) {
        return genResults(ex.getCode(),ex.getMsg(),null);
    }

    public static BaseResults fail(Integer code,String msg) {
        return genResults(code,msg,null);
    }

    public static BaseResults timeoutError() {
        return genResults(1501,"服务响应超时");
    }

    public static BaseResults toLogin(){
        return genResults(ExceptionEnum.NOT_LOGIN.getCode(),ExceptionEnum.NOT_LOGIN.getMsg());
    }

    public boolean isSuccess(){
        return this.code == 0;
    }

}
